#include <amxmodx>
#include <fakemeta_util>
#include <rpgx>

#define DMG_RADIUS 225.0
#define DMG_INTERVAL 1.0

new upgrade_id;

public plugin_init(){
	register_plugin("PoisonSmoke RPGx Upgrade", "2.1", "roflmao456");
	register_forward(FM_EmitSound, "smoke_damage");
	}

public RPGx_OnPluginReady()
	upgrade_id = RPGx_MakeUpgrade("PoisonSmoke", 5, 10, 10);

public smoke_damage(ent, channel, const sound[], Float:volume, Float:attenuation, flags, pitch){
	if(equal(sound, "weapons/sg_explode.wav")){
		new attacker = pev(ent, pev_owner);
		if(RPGx_GetUpgradeLevel(attacker, upgrade_id)){
			new origin[3];
			get_user_origin(attacker, origin);
			
			set_task(DMG_INTERVAL, "do_damage", attacker, origin, 3, "a", 20);
			}
		}
	return FMRES_IGNORED;
	}

public do_damage(origin[3], id){
	new level = RPGx_GetUpgradeLevel(id, upgrade_id);
	if(level){
		new Float:originF[3], victim = -1;
		IVecFVec(origin, originF);
		
		while((victim = engfunc(EngFunc_FindEntityInSphere, victim, originF, DMG_RADIUS))){
			if(is_user_alive(victim))
				fm_fakedamage(victim, "trigger_hurt", float(level), DMG_NERVEGAS);
			}
		}
	}